﻿using Core.Manager;
using Core.UI;
using Core.UI.UISub;
using Cysharp.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace Game.UI.Example
{
    public class MenuPanel : UIPanelBase
    {
        public Button startBtn;
        public Button settingBtn;
        public Button charBtn;
        public Button quitBtn;

        protected override void Awake()
        {
            base.Awake();
            startBtn.onClick.AddListener(OnClickGameStart);
            settingBtn.onClick.AddListener(OnClickSetting);
            charBtn.onClick.AddListener(OnClickShowCharPanel);
            quitBtn.onClick.AddListener(OnClickQuitGame);
        }

        private void OnClickQuitGame()
        {
            if (Application.isEditor)
            {
#if UNITY_EDITOR
                EditorApplication.isPlaying = false;
#endif
            }
            else
            {
                Application.Quit();
            }
        }

        private void OnClickShowCharPanel()
        {
            UIManager.Ins.ShowUI(UIPanelName.CharacterPanel).Forget();
        }

        private void OnClickSetting()
        {
            UIManager.Ins.ShowUI(UIWindowName.MenuSettingWindow, ui =>
            {
                MenuSettingWindow menuSettingWindow = (MenuSettingWindow)ui;
                menuSettingWindow.SetSettingType(MenuSettingWindow.SettingType.InMainMenu);
            }).Forget();
        }

        private void OnClickGameStart()
        {
            GameSceneManager.Ins.LoadScene("ui_2").Forget();
        }
    }
}